package edu.zju.udms.dnavigator.core.server;

import org.apache.log4j.Logger;

import edu.zju.udms.dnavigator.core.config.Configuration;
import edu.zju.udms.dnavigator.core.config.ConfigurationImpl;
import edu.zju.udms.dnavigator.core.extract.ExtractEngineImpl;
import edu.zju.udms.dnavigator.core.repository.LuceneRepository;
import edu.zju.udms.dnavigator.core.repository.Repository;

public class DNavigator {
	private final static Logger logger=Logger.getLogger(DNavigator.class);
	
	public static void main(String[] args) {
		Configuration configuration = null;
		Repository repository = null;
		Thread extractEngineThread = null;
		try {
			configuration = new ConfigurationImpl();
		} catch (Exception e) {
			logger.error("Configuration init failed", e);
			System.exit(-1);
		}
		try {
			repository = new LuceneRepository(configuration);
		} catch (Exception e) {
			logger.error("LuceneRepository init failed", e);
			System.exit(-1);
		}
		extractEngineThread = new Thread(new ExtractEngineImpl(configuration, repository));
		extractEngineThread.start();
		try {
			WebService webService = new WebService(configuration, repository);
			webService.service();
		} catch (Exception e) {
			logger.error("",e);
			System.exit(-1);
		}
		try {
			extractEngineThread.join();
		} catch (InterruptedException e) {
			logger.error("", e);
		}
	} 
}
